package someTestExcemple.huaweiOd.regularExpression;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//华为OD机试 - 提取字符串中最长数学表达式 - 正则表达式（Java 2024 D卷 100分）
//https://blog.csdn.net/guorui_java/article/details/140571423
public class ExpressionOfTheLongestNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
    }
    public static int findExpressionOfTheLongestNumber(String str) {
        Pattern pattern = Pattern.compile("^\\d+([+\\-*]\\d)+$");
        Matcher matcher = pattern.matcher(str);
        int maxLen = Integer.MIN_VALUE;
        long value = 0;
        while(matcher.find()) {
            String findStr = matcher.group();
            if(findStr.length() > maxLen) {
                value = calculateValue(findStr);
            }
        }
        //没找到返回0
        return 0;
    }
    public static long calculateValue(String str) {
        //数字
        String[] numbers = str.split("[+\\-*]");
        List<Character> operaters = new ArrayList<>();
        //数字的个数一定会比操作符个数多一个
        int result = 0;
        for(char c : str.toCharArray()) {
            if(c =='+'|| c=='-'||c=='*') {
                operaters.add(c);
            }
        }
        for(int i=0;i<operaters.size();i++){
            if(operaters.get(i)=='*') {
                result+= Integer.parseInt(numbers[i]) *Integer.parseInt(numbers[i+1]);
            }
        }
        return 0;
    }
}
